package com.singfan.core.dao.database.impl;

import com.singfan.common.db.DaoBaseGeneric;
import com.singfan.common.db.DbContext;
import com.singfan.common.db.config.Table;
import com.singfan.core.dao.database.IBarberCommentDao;
import com.singfan.core.dao.database.model.BarberComment;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * Author: hansonghe
 * Date: 2015-08-19 12:12
 * Desc:
 */
@Repository
public class BarberCommentDaoImpl extends DaoBaseGeneric<BarberComment> implements IBarberCommentDao {
    @Override
    protected String getTableName(Object hashKey) {
        return tableNameBase;
    }

    @Override
    protected String getDatabaseId(Object hashKey) {
        return "app_1";
    }

    @Override
    public void create(BarberComment barberComment) {
        insert(barberComment.getBarberId(), barberComment);
    }

    @Override
    public List<BarberComment> selectBarberCommentList(long barberId, int pageIndex, int pageSize, boolean satisfaction) {
        String sql;
        if (satisfaction){
            sql = "SELECT * FROM " + getTableName(barberId) + " WHERE barber_id=? AND comment_star>=6 limit ?,?";
        }
        else {
            sql = "SELECT * FROM " + getTableName(barberId) + " WHERE barber_id=? AND comment_star<6 limit ?,?";
        }

        return selectList(null, sql, barberId, pageIndex*pageSize, pageSize);
    }

    @Override
    public List<BarberComment> selectBarberCommentList(long barberId, int pageIndex, int pageSize) {
        String sql = "SELECT * FROM " + getTableName(barberId) + " WHERE barber_id=? limit ?,?";
        return selectList(null, sql, barberId, pageIndex*pageSize, pageSize);
    }
}
